<?php

namespace IDock\Insurance\DAJIA\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\DAJIA\Response\AllDAJIAResponse;
use IDock\Printer\PolicyPaymentPrinter;
use IDock\Printer\ProposalStatusPrinter;

class NonCarOrderQueryResponse extends AllDAJIAResponse
{

    public function printerInit(): Response
    {
        $proposalStatusPrinter = new ProposalStatusPrinter();

        $result = $this->get('body', []) ?? [];
        if(!in_array($result['status'],['2000','0001'])){
            $this->setError($result['message'] ?? '');
            $this->printer = $proposalStatusPrinter;
            return $this;
        }
        $pdfList = [];
        $arr = [];
        foreach (($result['policyInfos'] ?? []) as $val){
            if($val['CAppStatus'] == '5'){
                $proposalStatusPrinter->statusCode = 'U5';
                $proposalStatusPrinter->status = IDockEnums::$underStats[$proposalStatusPrinter->statusCode];
                $arr[$val['CAppNo']] = $val['CPlyNo'] ?? '';
                $pdfList[$val['CPlyNo']] = $val['CPdfUrl'];
            }
        }

        $proposalStatusPrinter->argc['policyArr'] = $arr;
        $proposalStatusPrinter->argc['pdfList'] = $pdfList;
        $this->printer = $proposalStatusPrinter;
        return $this;
    }
}
